/**
 * 
 */
package com.agrec.client;

import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.TextBox;

/**
 * @author allomeen
 * This is a spedcial textBox that has shaded text inside when
 * clicked, the text disapper. It also has could remove a 
 * style name after clicked
 * Default CSS classes: shaddedText, errorTextBox
 *
 */
public class AGRecTextBox extends TextBox implements ClickHandler {

	private String shadedText;
	private String shadedTextStyle;
	private String errorStyle;

	//creating a regular textBox, if clickHandler is needed just create one and override this
	public AGRecTextBox() {
		// TODO Auto-generated constructor stub
	}

	public AGRecTextBox(String shadedText) {
		this.shadedText = shadedText;
		this.shadedTextStyle = "shadedText";
		this.errorStyle = "errorStyle";
		addStyleName(shadedTextStyle);
		setValue(shadedText);
		addClickHandler(this);
	}

	/**
	 * @param element
	 */
	public AGRecTextBox(Element element, String shadedText) {
		super(element);
		
		this.shadedText = shadedText;
		addStyleName(shadedTextStyle);
		setValue(shadedText);
		addClickHandler(this);
	}

	
	public void onClick(ClickEvent event) {
		if(getText().equals(shadedText)){
			setText("");
			removeStyleName(shadedTextStyle);
			
		}
		removeStyleName(errorStyle);
		
	}
	
	public void addShadedTextStyleName(String shadedTextStyle){
		this.shadedTextStyle = shadedTextStyle;
		addStyleName(shadedTextStyle);
	}
	
	public void addErrorStyleName(String errorStyle){
		this.errorStyle = errorStyle;
		addStyleName(errorStyle);
	}

}
